$(function () {
    /* 从本地获取借款类型 */
    let applyfortype = localStorage.getItem('applyfortype')
    // console.log(JSON.parse(localStorage.getItem('yhm')).id);

    // 判断
    switch (applyfortype) {
        case '1':
            $('#repayType').addClass('btn-primary').html('信用贷')
            break;
        case '2':
            $('#repayType').addClass('btn-warning').html('车易贷')
            break;
        case '3':
            $('#repayType').addClass('btn-primary').html('房易贷')
            break;
    }


    $('#submitApplyForm').on('click', function () {
        /* 发送借款申请的ajax */
        let params = {
            userid: JSON.parse(localStorage.getItem('yhm')).id,
            borrowType: applyfortype,
            borrowmoney: $('#borrowmoney').val(),
            interest: $('#interest').val(),
            borrowtime: $('#borrowtime').val(),
            repaytype: $('input[type="radio"]:checked').val(),
            minbid: $('#minbid').val(),
            bouns: $('#bouns').val(),
            days: $('#days').val(),
            title: $('#title').val(),
            info: $('#info').val(),
        }
        $.ajax({
            url: 'http://139.9.177.51:3333/p2p/borrow',
            type: 'post',
            data: params,
            success: function (data) {
                let {
                    code,
                    msg
                } = data;
                if (code === 200) {
                    alert(msg)
                    location.href = "../index.html"
                } else {
                    alert(msg)
                }
            }
        })
    })
})